package com.uhealin.wt.boot.action;

import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import lava.rt.instance.MethodInstance;
import lava.wt.template.ActionTemplate;
import lava.wt.template.LSSqlActionTemplate;

public abstract class LSSqlAction extends LSSqlActionTemplate {

	@Autowired
	HttpServletRequest request;
	
	@Autowired
	HttpServletResponse response;
	
	@Autowired
	HttpSession session;
	
	@Autowired
	JdbcTemplate jdbcTemplate;
	
	Connection connection;
	
	@Override
	public HttpServletRequest getRequest() {
		// TODO Auto-generated method stub
		return this.request;
	}

	@Override
	public HttpServletResponse getResponse() {
		// TODO Auto-generated method stub
		return this.response;
	}

	@Override
	public HttpSession getSession() {
		// TODO Auto-generated method stub
		return this.session;
	}

	@Override
	public Connection createConnection() throws SQLException {
		// TODO Auto-generated method stub
		if(this.connection==null) {
		  this.connection= jdbcTemplate.getDataSource().getConnection();
		}
		return this.connection;
	}

	

	@Override
	protected String createPageSql(String dataSql, int start, int limit) {
		// TODO Auto-generated method stub
		return dataSql+" limit "+start+","+limit;
	}

	

	@Override
	public void onConnectionEnd(Connection connection) {
		// TODO Auto-generated method stub
		MethodInstance.close.invoke(connection);
	}


	

	
	
	
}
